import { Leafer } from "leafer-ui";
import { Black } from "./black";
import { moveBlack } from "./moveBlack";

class Sprite {
  sprite: Map<string, moveBlack> = new Map();
  drawList: Black[] = [];
  leafer: Leafer | undefined;
  add(id: string, moveBlack: moveBlack) {
    this.sprite.set(id, moveBlack);
    return id;
  }
  remove(id: string) {
    this.sprite.delete(id);
  }
  addDraw(draw: Black) {
    if (this.leafer) return this.leafer.add(draw.targter);
    this.drawList.push(draw);
  }
  draw(leafer: Leafer) {
    this.leafer = leafer;
    this.drawList.forEach((item) => {
      leafer.add(item.targter);
    });
  }
  run() {
    this.sprite.forEach((item) => {
      item.draw();
    });
  }
}
export const sprite = new Sprite();
